<template>
  <div>
    <!-- 附件表五 基本信息及燃耗信息 add by qzn 20190710  -->
    <mt-header fixed title="道路货物运输量专项调查" style="z-index: 999999;">
      <span slot="left" @click="goBack">
        <mt-button icon="back" slot="left">返回</mt-button>
      </span>
      <!-- <mt-button  v-if="(reportedByOther==1&&information=='调查员'||reportedByOther==0&&information=='业户')" icon slot="right" @click.native="insertDate">新增</mt-button> -->
    </mt-header>
    <el-table border :data="tableData4" style="width: 100%" max-height="450">
      <el-table-column fixed prop="xh" label="序号" width="50" align="center"></el-table-column>
      <el-table-column prop="cphm" label="车牌号码" width="80" align="center"></el-table-column>
      <el-table-column prop="cpys" label="车牌颜色" width="80" align="center"></el-table-column>
      <el-table-column prop="tcxhj" label="趟次数合计（个）" width="100" align="center"></el-table-column>

      <el-table-column prop="rjxslc" label="总行驶里程（公里）" width="100" align="center"></el-table-column>
      <el-table-column prop="bglrh" label="载货里程（公里）" width="100" align="center"></el-table-column>
      <el-table-column prop="lclyl" label="高速公路里程（公里）" width="120" align="center"></el-table-column>

      <el-table-column prop="dcqhyl" label="调查期货运量（吨）" width="120" align="center"></el-table-column>
      <el-table-column prop="dcqhylzzl" label="调查期货物周转量（吨公里）" width="140" align="center"></el-table-column>
      <el-table-column prop="dcqpjyj" label="调查期平均运距（公里）" width="120" align="center"></el-table-column>

      
      <el-table-column prop="dwlyl" label="能耗（升/立方米/千克/千瓦时）" width="120" align="center"></el-table-column>

    </el-table>
  </div>
</template>
      
<script>
import {Toast} from 'mint-ui'
export default {
  data() {
    return {
      xh: 0, //序号
      tableData4: [
        {
          recid: "",
          floatorder: "",
          xh: "0",
          cphm: "", // 车牌号码
          cpys: "", // 车牌颜色
          tcxhj: "",
          rjxslc: "",
          bglrh: "",
          dcqhyl: "",
          dcqhylzzl: "",
          dcqpjyj: "",
          lclyl: "",
          dwlyl: "",
        }
      ],
      // 根据公司状态判定新增按钮是否显示 add by qzn 20190625
      reportedByOther: this.$route.query.reportedByOther,
      information: this.$route.query.information
    };
  },
  watch: {},
  mounted() {
    
    this.getCphList();
  },
  methods: {
    goBack() {
      //点击后退
      this.$router.go(-1);
    },
    getCphList() {
      let data = {};
      data.yhmlkRecid = this.$route.query.yhmlk;
      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/assit/findFzdcbfd05",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            if (result.data.status == "1000") {
              this.tableData4.splice(0);
              let cphList = [];
              if(result.data.data.MSG == "没有查询到结果"){
                  cphList.push("nodata");
                  localStorage.setItem("cphList",cphList);
              } else {
                  result.data.data.Fzdcbfd05.forEach(item => {
                    cphList.push(item.fzdcbfd52019001);
                  });
                  localStorage.setItem("cphList",cphList);
              }

              console.log("cphList:"+localStorage.getItem("cphList"));

              if(localStorage.getItem("cphList") != "nodata"){
                this.getCode();
              } else {
                Toast("暂无数据");
                this.tableData4.splice(0);
              }
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
    },
                getCarColorName(code) {
                  var goodsTypes = [
                    {
                      code: "1",
                      name: "蓝色"
                    },
                    {
                      code: "2",
                      name: "黄色"
                    },
                    {
                      code: "3",
                      name: "黑色"
                    },
                    {
                      code: "4",
                      name: "白色"
                    },
                    {
                      code: "5",
                      name: "黄绿"
                    },
                    {
                      code: "6",
                      name: "渐变绿"
                    },
                    {
                      code: "9",
                      name: "其他"
                    }
                  ];
                  var name;
                  goodsTypes.forEach(item => {
                    if (item.code === code) {
                      name = item.name;
                    }
                  });
                  return name;
              },
    getCode() {
      let data = {};      
      let vehicleNoList = [];
      if(localStorage.getItem("cphList").indexOf(",") > 0){
         vehicleNoList = localStorage.getItem("cphList").split(',')  
      } else {
         vehicleNoList.push(localStorage.getItem("cphList"));
      }
      data.vehicleNoList = vehicleNoList;

      console.log("data---------"+JSON.stringify(data));

      this.axios
        .post(
          "http://zxdc.catsic.com:9090/sampling/assit/autoTotalFzdcbfd06",
          { data: data },
          {
            headers: {
              "Content-Type": "application/json",
              mobileHeader:
                '{"sessionId":' + localStorage.getItem("sessionId") + "}"
            }
          }
        )
        .then(
          result => {
            console.log("辅助表-自动计算返回："+JSON.stringify(result));
            if (result.data.status == "1000") {
                this.tableData4.splice(0);
                let AutoTotalTable = [];
                AutoTotalTable = JSON.stringify(result.data.data.AutoTotalTable);
                
               result.data.data.AutoTotalTable.forEach(item => {
                    let tableData = {};
                    tableData.xh = ++this.xh;
                    tableData.cphm = item.vehicleNo;
                    tableData.cpys = this.getCarColorName(item.plateColorCode);
                    tableData.tcxhj = item.fzdcbfd52019015;
                    tableData.rjxslc = item.fzdcbfd52019016;
                    tableData.bglrh = item.fzdcbfd52019017;
                    tableData.dcqhyl = item.fzdcbfd52019018;
                    tableData.dcqhylzzl = item.fzdcbfd52019019;
                    tableData.dcqpjyj = item.fzdcbfd52019020;
                    tableData.lclyl = item.fzdcbfd52019021;
                    tableData.dwlyl = item.fzdcbfd52019022;
                    this.tableData4.push(tableData);
                });

                
            } else if (result.data.status == "5001") {
              this.tableData4.splice(0);
                Toast(result.data.msg);
            }
          },
          error => {
            console.log("getyhcars request error:" + error);
          }
        );
    }
  }
};
</script>